'''
Created on 28.2.2011

@author: Martin Vegi Kysel
'''

from PyStats.MannWhitneyFunction import MannWhitney

#fileName = "../Processed_Franz_NoHe_retrain.gngpol.log.txt"
#sessionOnly = 0
#print fileName


def readProcessedFile(fileName, sessionOnly):
    infile = open(fileName, 'rU') #'U' means Universal newlines - works equally on Mac, PC Unix.
    x = []
    y = []
    
    i = 0;
    print infile
    
    for line in infile:
        #print line
        i+=1
        if i>1: # skip the header
            parts = line.split()
            
            if sessionOnly!=0 and int(parts[0])!=sessionOnly :
                #print "Skipping ",i
                continue
            
            #print parts[0]
            
            if int(parts[2])==1:
                y.append(float(parts[4]))
            if int(parts[2])==2:
                #print parts[0]+"/"+parts[1]+"/"+parts[3]
                #print line
                x.append(float(parts[4]))
                
            #if len(x)>=20 or len(y)>=20:
                #break
    result = [-1,-1,-1,-1]
    
    #print x
    #print y
    
    if len(x)>0 and len(y)>0:
        result = MannWhitney(x, y)
    
    return result


#to start this use something as:

#outcome = readProcessedFile("./../../../output/GnG_Analysis/Hannes_snailtraingngpollog/Normalized_Hannes_snailtrain.gngpol.log", 1)
#print outcome